



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class AreaDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public AreaDB()
        {
        }

        public AreaDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<Area> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<Area> lstRet = new List<Area>();

            string strQuery = " select " + strTop  + " * from dbo.[Area]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Area obj = new Area();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["AreaNameAR"] != DBNull.Value)
                    {
                        obj.AreaNameAR = (System.String)dr["AreaNameAR"];
                    }
                    else
                    {
                        obj.AreaNameAR = "";
                    } 
 if (dr["AreaNameEN"] != DBNull.Value)
                    {
                        obj.AreaNameEN = (System.String)dr["AreaNameEN"];
                    }
                    else
                    {
                        obj.AreaNameEN = "";
                    } 
 if (dr["ParentID"] != DBNull.Value)
                    {
                        obj.ParentID = (System.Int64?)dr["ParentID"];
                    }
                    else
                    {
                        obj.ParentID = null;
                    } 
 if (dr["Code"] != DBNull.Value)
                    {
                        obj.Code = (System.String)dr["Code"];
                    }
                    else
                    {
                        obj.Code = "";
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<Area> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Area> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , Area obj)
        {
            
            

                    DbParameter prmAreaNameAR = con.createParameter();
                    prmAreaNameAR.ParameterName = "@AreaNameAR";
                    prmAreaNameAR.DbType =DbType.String;
                    if (obj.AreaNameAR == null)
                    {
                        prmAreaNameAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmAreaNameAR.Value = obj.AreaNameAR;
                    }
                

                    


                    DbParameter prmAreaNameEN = con.createParameter();
                    prmAreaNameEN.ParameterName = "@AreaNameEN";
                    prmAreaNameEN.DbType =DbType.String;
                    if (obj.AreaNameEN == null)
                    {
                        prmAreaNameEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmAreaNameEN.Value = obj.AreaNameEN;
                    }
                

                    


                    DbParameter prmParentID = con.createParameter();
                    prmParentID.ParameterName = "@ParentID";
                    prmParentID.DbType =DbType.Int64;
                    if (obj.ParentID == null)
                    {
                        prmParentID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmParentID.Value = obj.ParentID;
                    }
                

                    


                    DbParameter prmCode = con.createParameter();
                    prmCode.ParameterName = "@Code";
                    prmCode.DbType =DbType.String;
                    if (obj.Code == null)
                    {
                        prmCode.Value = DBNull.Value;
                    }
                    else
                    {
                        prmCode.Value = obj.Code;
                    }
                

                    


           



            string strQuery = " insert into dbo.[Area] ([AreaNameAR],[AreaNameEN],[ParentID],[Code]) VALUES (@AreaNameAR,@AreaNameEN,@ParentID,@Code) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmAreaNameAR,prmAreaNameEN,prmParentID,prmCode);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(Area obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, Area obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmAreaNameAR = con.createParameter();
                    prmAreaNameAR.ParameterName = "@AreaNameAR";
                    prmAreaNameAR.DbType =DbType.String;
                    if (obj.AreaNameAR == null)
                    {
                        prmAreaNameAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmAreaNameAR.Value = obj.AreaNameAR;
                    }
                

                    


                    DbParameter prmAreaNameEN = con.createParameter();
                    prmAreaNameEN.ParameterName = "@AreaNameEN";
                    prmAreaNameEN.DbType =DbType.String;
                    if (obj.AreaNameEN == null)
                    {
                        prmAreaNameEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmAreaNameEN.Value = obj.AreaNameEN;
                    }
                

                    


                    DbParameter prmParentID = con.createParameter();
                    prmParentID.ParameterName = "@ParentID";
                    prmParentID.DbType =DbType.Int64;
                    if (obj.ParentID == null)
                    {
                        prmParentID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmParentID.Value = obj.ParentID;
                    }
                

                    


                    DbParameter prmCode = con.createParameter();
                    prmCode.ParameterName = "@Code";
                    prmCode.DbType =DbType.String;
                    if (obj.Code == null)
                    {
                        prmCode.Value = DBNull.Value;
                    }
                    else
                    {
                        prmCode.Value = obj.Code;
                    }
                

                    


           



            string strQuery = " update dbo.[Area] set [AreaNameAR]=@AreaNameAR,[AreaNameEN]=@AreaNameEN,[ParentID]=@ParentID,[Code]=@Code where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmAreaNameAR,prmAreaNameEN,prmParentID,prmCode);

            

        }


        public void Update(Area obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, Area obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[Area]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( Area obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<Area> getAreaByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<Area> lstRet = new List<Area>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<Area> getAreaByID(System.Int64 ID)
                    {
                        List<Area> lstRet = new List<Area>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getAreaByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Area> getAreaByAreaNameAR(ClassDataHandler con,System.String AreaNameAR)
                    {
                        List<Area> lstRet = new List<Area>();


                        DbParameter prmAreaNameAR = con.createParameter();
                        prmAreaNameAR.ParameterName = "@AreaNameAR";
                        prmAreaNameAR.DbType = DbType.String;
                        if (AreaNameAR == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmAreaNameAR.Value = AreaNameAR;
                        }


                        lstRet = Select(con, "" , " where [AreaNameAR]=@AreaNameAR ", prmAreaNameAR);



                        return lstRet;

                    }


                    public List<Area> getAreaByAreaNameAR(System.String AreaNameAR)
                    {
                        List<Area> lstRet = new List<Area>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getAreaByAreaNameAR(con, AreaNameAR);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Area> getAreaByAreaNameEN(ClassDataHandler con,System.String AreaNameEN)
                    {
                        List<Area> lstRet = new List<Area>();


                        DbParameter prmAreaNameEN = con.createParameter();
                        prmAreaNameEN.ParameterName = "@AreaNameEN";
                        prmAreaNameEN.DbType = DbType.String;
                        if (AreaNameEN == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmAreaNameEN.Value = AreaNameEN;
                        }


                        lstRet = Select(con, "" , " where [AreaNameEN]=@AreaNameEN ", prmAreaNameEN);



                        return lstRet;

                    }


                    public List<Area> getAreaByAreaNameEN(System.String AreaNameEN)
                    {
                        List<Area> lstRet = new List<Area>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getAreaByAreaNameEN(con, AreaNameEN);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Area> getAreaByParentID(ClassDataHandler con,System.Int64? ParentID)
                    {
                        List<Area> lstRet = new List<Area>();


                        DbParameter prmParentID = con.createParameter();
                        prmParentID.ParameterName = "@ParentID";
                        prmParentID.DbType = DbType.Int64;
                        if (ParentID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmParentID.Value = ParentID;
                        }


                        lstRet = Select(con, "" , " where [ParentID]=@ParentID ", prmParentID);



                        return lstRet;

                    }


                    public List<Area> getAreaByParentID(System.Int64? ParentID)
                    {
                        List<Area> lstRet = new List<Area>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getAreaByParentID(con, ParentID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Area> getAreaByCode(ClassDataHandler con,System.String Code)
                    {
                        List<Area> lstRet = new List<Area>();


                        DbParameter prmCode = con.createParameter();
                        prmCode.ParameterName = "@Code";
                        prmCode.DbType = DbType.String;
                        if (Code == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmCode.Value = Code;
                        }


                        lstRet = Select(con, "" , " where [Code]=@Code ", prmCode);



                        return lstRet;

                    }


                    public List<Area> getAreaByCode(System.String Code)
                    {
                        List<Area> lstRet = new List<Area>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getAreaByCode(con, Code);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<Area> Search(ClassDataHandler con, Area obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.AreaNameAR != "")
                    {
                        DbParameter prmAreaNameAR = con.createParameter();
                        prmAreaNameAR.ParameterName = "@AreaNameAR";
                        prmAreaNameAR.DbType =DbType.String;
                        if (obj.AreaNameAR == null)
                        {
                            prmAreaNameAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmAreaNameAR.Value = obj.AreaNameAR;
                        }
                        strWhere += " [AreaNameAR]=@AreaNameAR AND ";
                        lstParameters.Add(prmAreaNameAR);
                     }



                    

                    if (obj.AreaNameEN != "")
                    {
                        DbParameter prmAreaNameEN = con.createParameter();
                        prmAreaNameEN.ParameterName = "@AreaNameEN";
                        prmAreaNameEN.DbType =DbType.String;
                        if (obj.AreaNameEN == null)
                        {
                            prmAreaNameEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmAreaNameEN.Value = obj.AreaNameEN;
                        }
                        strWhere += " [AreaNameEN]=@AreaNameEN AND ";
                        lstParameters.Add(prmAreaNameEN);
                     }



                    

                    if (obj.ParentID != null)
                    {
                        DbParameter prmParentID = con.createParameter();
                        prmParentID.ParameterName = "@ParentID";
                        prmParentID.DbType =DbType.Int64;
                        if (obj.ParentID == null)
                        {
                            prmParentID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmParentID.Value = obj.ParentID;
                        }
                        strWhere += " [ParentID]=@ParentID AND ";
                        lstParameters.Add(prmParentID);
                     }



                    

                    if (obj.Code != "")
                    {
                        DbParameter prmCode = con.createParameter();
                        prmCode.ParameterName = "@Code";
                        prmCode.DbType =DbType.String;
                        if (obj.Code == null)
                        {
                            prmCode.Value = DBNull.Value;
                        }
                        else
                        {
                            prmCode.Value = obj.Code;
                        }
                        strWhere += " [Code]=@Code AND ";
                        lstParameters.Add(prmCode);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<Area> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Area> Search(Area obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Area> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<Area> SearchOrLike(ClassDataHandler con, Area obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.AreaNameAR != "")
                    {
                        DbParameter prmAreaNameAR = con.createParameter();
                        prmAreaNameAR.ParameterName = "@AreaNameAR";
                        prmAreaNameAR.DbType =DbType.String;
                        if (obj.AreaNameAR == null)
                        {
                            prmAreaNameAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmAreaNameAR.Value = obj.AreaNameAR;
                        }
                        strWhere += " [AreaNameAR] LIKE @AreaNameAR OR ";
                        lstParameters.Add(prmAreaNameAR);
                     }



                    

                    if (obj.AreaNameEN != "")
                    {
                        DbParameter prmAreaNameEN = con.createParameter();
                        prmAreaNameEN.ParameterName = "@AreaNameEN";
                        prmAreaNameEN.DbType =DbType.String;
                        if (obj.AreaNameEN == null)
                        {
                            prmAreaNameEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmAreaNameEN.Value = obj.AreaNameEN;
                        }
                        strWhere += " [AreaNameEN] LIKE @AreaNameEN OR ";
                        lstParameters.Add(prmAreaNameEN);
                     }



                    

                    if (obj.ParentID != null)
                    {
                        DbParameter prmParentID = con.createParameter();
                        prmParentID.ParameterName = "@ParentID";
                        prmParentID.DbType =DbType.Int64;
                        if (obj.ParentID == null)
                        {
                            prmParentID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmParentID.Value = obj.ParentID;
                        }
                        strWhere += " [ParentID]=@ParentID OR ";
                        lstParameters.Add(prmParentID);
                     }



                    

                    if (obj.Code != "")
                    {
                        DbParameter prmCode = con.createParameter();
                        prmCode.ParameterName = "@Code";
                        prmCode.DbType =DbType.String;
                        if (obj.Code == null)
                        {
                            prmCode.Value = DBNull.Value;
                        }
                        else
                        {
                            prmCode.Value = obj.Code;
                        }
                        strWhere += " [Code] LIKE @Code OR ";
                        lstParameters.Add(prmCode);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<Area> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Area> SearchOrLike(Area obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Area> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            